package com.yy.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.jsoup.Jsoup;
/**
 * @Description:
 * @ClassName: ImageUtils
 * @author: 姚欣宏
 * @date: 2023.07.10
 */
public class ImageUtils {
    public static String recognition(String base64) {
        String username = "ecloudunion2";
        String password = "yiyun202305";
        String remark = "";
        Map data = new HashMap();
        data.put("username", username);
        data.put("password", password);
        data.put("typeid", "1");
        data.put("remark", remark);
        data.put("image", base64);
        String resultString = null;

        try {
            resultString = Jsoup.connect("http://api.ttshitu.com/predict").requestBody(JSON.toJSONString(data)).header("Content-Type", "application/json").ignoreContentType(true).timeout(120000).post().text();
        } catch (IOException var8) {
            var8.printStackTrace();
        }

        JSONObject jsonObject = JSONObject.parseObject(resultString);
        String result = null;
        if (jsonObject.getBoolean("success")) {
            result = jsonObject.getJSONObject("data").getString("result");
            System.out.println("识别成功结果为:" + result);
        } else {
            System.out.println("识别失败原因为:" + jsonObject.getString("message"));
        }

        return result;
    }
}
